home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.src.lzh / libc / getdate.c < prev    next >
C/C++ Source or Header  |  1989-07-05  |  28KB  |  1,171 lines

  1. # define ID 257
  2. # define MONTH 258
  3. # define DAY 259
  4. # define MERIDIAN 260
  5. # define NUMBER 261
  6. # define UNIT 262
  7. # define MUNIT 263
  8. # define SUNIT 264
  9. # define ZONE 265
  10. # define DAYZONE 266
  11. # define AGO 267
  12.  
  13. # line 3 "getdate.y"
  14.     /*     Steven M. Bellovin (unc!smb)            */
  15.     /*    Dept. of Computer Science            */
  16.     /*    University of North Carolina at Chapel Hill    */
  17.     /*    @(#)getdate.y    2.13    9/16/86 */
  18.  
  19. #include <sys/types.h>
  20. #ifndef AMIGA
  21. # include <sys/timeb.h>
  22. #endif /* AMIGA */
  23. #include <ctype.h>
  24. #include <time.h>
  25.  
  26. #define    NULL    0
  27.  
  28. #define daysec (24L*60L*60L)
  29.  
  30.     static int timeflag, zoneflag, dateflag, dayflag, relflag;
  31.     static time_t relsec, relmonth;
  32.     static int hh, mm, ss, merid, daylght;
  33.     static int dayord, dayreq;
  34.     static int month, day, year;
  35.     static int ourzone;
  36.  
  37. #define AM 1
  38. #define PM 2
  39. #define DAYLIGHT 1
  40. #define STANDARD 2
  41. #define MAYBE    3
  42. #define yyclearin yychar = -1
  43. #define yyerrok yyerrflag = 0
  44. extern int yychar;
  45. extern int yyerrflag;
  46. #ifndef YYMAXDEPTH
  47. #define YYMAXDEPTH 150
  48. #endif
  49. #ifndef YYSTYPE
  50. #define YYSTYPE int
  51. #endif
  52. YYSTYPE yylval, yyval;
  53. typedef int yytabelem;
  54. # define YYERRCODE 256
  55.  
  56. # line 108 "getdate.y"
  57.  
  58.  
  59. static int mdays[12] =
  60.     {31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
  61. #define epoch 1970
  62.  
  63. extern struct tm *localtime();
  64. time_t dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
  65. int mm, dd, yy, h, m, s, mer, zone, dayflag;
  66. {
  67.     time_t tod, jdate;
  68.     register int i;
  69.     time_t timeconv();
  70.  
  71.     if (yy < 0) yy = -yy;
  72.     if (yy < 100) yy += 1900;
  73.     mdays[1] = 28 + (yy%4 == 0 && (yy%100 != 0 || yy%400 == 0));
  74.     if (yy < epoch || yy > 1999 || mm < 1 || mm > 12 ||
  75.         dd < 1 || dd > mdays[--mm]) return (-1);
  76.     jdate = dd-1;
  77.         for (i=0; i<mm; i++) jdate += mdays[i];
  78.     for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0);
  79.     jdate *= daysec;
  80.     jdate += zone * 60L;
  81.     if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
  82.     jdate += tod;
  83.     if (dayflag==DAYLIGHT || (dayflag==MAYBE&&localtime(&jdate)->tm_isdst))
  84.         jdate += -1*60*60;
  85.     return (jdate);
  86. }
  87.  
  88. time_t dayconv(ord, day, now) int ord, day; time_t now;
  89. {
  90.     register struct tm *loctime;
  91.     time_t tod;
  92.     time_t daylcorr();
  93.  
  94.     tod = now;
  95.     loctime = localtime(&tod);
  96.     tod += daysec * ((day - loctime->tm_wday + 7) % 7);
  97.     tod += 7*daysec*(ord<=0?ord:ord-1);
  98.     return daylcorr(tod, now);
  99. }
  100.  
  101. time_t timeconv(hh, mm, ss, mer) register int hh, mm, ss, mer;
  102. {
  103.     if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
  104.     switch (mer) {
  105.         case AM: if (hh < 1 || hh > 12) return(-1);
  106.              return (60L * ((hh%12)*60L + mm)+ss);
  107.         case PM: if (hh < 1 || hh > 12) return(-1);
  108.              return (60L * ((hh%12 +12)*60L + mm)+ss);
  109.         case 24: if (hh < 0 || hh > 23) return (-1);
  110.              return (60L * (hh*60L + mm)+ss);
  111.         default: return (-1);
  112.     }
  113. }
  114. time_t monthadd(sdate, relmonth) time_t sdate, relmonth;
  115. {
  116.     struct tm *ltime;
  117.     time_t dateconv();
  118.     time_t daylcorr();
  119.     int mm, yy;
  120.  
  121.     if (relmonth == 0) return 0;
  122.     ltime = localtime(&sdate);
  123.     mm = 12*ltime->tm_year + ltime->tm_mon + relmonth;
  124.     yy = mm/12;
  125.     mm = mm%12 + 1;
  126.     return daylcorr(dateconv(mm, ltime->tm_mday, yy, ltime->tm_hour,
  127.         ltime->tm_min, ltime->tm_sec, 24, ourzone, MAYBE), sdate);
  128. }
  129.  
  130. time_t daylcorr(future, now) time_t future, now;
  131. {
  132.     int fdayl, nowdayl;
  133.  
  134.     nowdayl = (localtime(&now)->tm_hour+1) % 24;
  135.     fdayl = (localtime(&future)->tm_hour+1) % 24;
  136.     return (future-now) + 60L*60L*(nowdayl-fdayl);
  137. }
  138.  
  139. static char *lptr;
  140.  
  141. yylex()
  142. {
  143.     extern int yylval;
  144.     int sign;
  145.     register char c;
  146.     register char *p;
  147.     char idbuf[20];
  148.     int pcnt;
  149.  
  150.     for (;;) {
  151.         while (isspace(*lptr)) lptr++;
  152.  
  153.         if (isdigit(c = *lptr) || c == '-' || c == '+') {
  154.             if (c== '-' || c == '+') {
  155.                 if (c=='-') sign = -1;
  156.                 else sign = 1;
  157.                 if (!isdigit(*++lptr)) {
  158.                     /* yylval = sign; return (NUMBER); */
  159.                     return yylex();    /* skip the '-' sign */
  160.                 }
  161.             } else sign = 1;
  162.             yylval = 0;
  163.             while (isdigit(c = *lptr++)) yylval = 10*yylval + c - '0';
  164.             yylval *= sign;
  165.             lptr--;
  166.             return (NUMBER);
  167.  
  168.         } else if (isalpha(c)) {
  169.             p = idbuf;
  170.             while (isalpha(c = *lptr++) || c=='.')
  171.                 if (p < &idbuf[sizeof(idbuf)-1])
  172.                     *p++ = c;
  173.             *p = '\0';
  174.             lptr--;
  175.             return (lookup(idbuf));
  176.         }
  177.  
  178.         else if (c == '(') {
  179.             pcnt = 0;
  180.             do {
  181.                 c = *lptr++;
  182.                 if (c == '\0') return(c);
  183.                 else if (c == '(') pcnt++;
  184.                 else if (c == ')') pcnt--;
  185.             } while (pcnt > 0);
  186.         }
  187.  
  188.         else return (*lptr++);
  189.     }
  190. }
  191.  
  192. struct table {
  193.     char *name;
  194.     int type, value;
  195. };
  196.  
  197. struct table mdtab[] = {
  198.     {"January", MONTH, 1},
  199.     {"February", MONTH, 2},
  200.     {"March", MONTH, 3},
  201.     {"April", MONTH, 4},
  202.     {"May", MONTH, 5},
  203.     {"June", MONTH, 6},
  204.     {"July", MONTH, 7},
  205.     {"August", MONTH, 8},
  206.     {"September", MONTH, 9},
  207.     {"Sept", MONTH, 9},
  208.     {"October", MONTH, 10},
  209.     {"November", MONTH, 11},
  210.     {"December", MONTH, 12},
  211.  
  212.     {"Sunday", DAY, 0},
  213.     {"Monday", DAY, 1},
  214.     {"Tuesday", DAY, 2},
  215.     {"Tues", DAY, 2},
  216.     {"Wednesday", DAY, 3},
  217.     {"Wednes", DAY, 3},
  218.     {"Thursday", DAY, 4},
  219.     {"Thur", DAY, 4},
  220.     {"Thurs", DAY, 4},
  221.     {"Friday", DAY, 5},
  222.     {"Saturday", DAY, 6},
  223.     {0, 0, 0}};
  224.  
  225. #define HRS *60
  226. #define HALFHR 30
  227. struct table mztab[] = {
  228.     {"a.m.", MERIDIAN, AM},
  229.     {"am", MERIDIAN, AM},
  230.     {"p.m.", MERIDIAN, PM},
  231.     {"pm", MERIDIAN, PM},
  232.     {"nst", ZONE, 3 HRS + HALFHR},        /* Newfoundland */
  233.     {"n.s.t.", ZONE, 3 HRS + HALFHR},
  234.     {"ast", ZONE, 4 HRS},        /* Atlantic */
  235.     {"a.s.t.", ZONE, 4 HRS},
  236.     {"adt", DAYZONE, 4 HRS},
  237.     {"a.d.t.", DAYZONE, 4 HRS},
  238.     {"est", ZONE, 5 HRS},        /* Eastern */
  239.     {"e.s.t.", ZONE, 5 HRS},
  240.     {"edt", DAYZONE, 5 HRS},
  241.     {"e.d.t.", DAYZONE, 5 HRS},
  242.     {"cst", ZONE, 6 HRS},        /* Central */
  243.     {"c.s.t.", ZONE, 6 HRS},
  244.     {"cdt", DAYZONE, 6 HRS},
  245.     {"c.d.t.", DAYZONE, 6 HRS},
  246.     {"mst", ZONE, 7 HRS},        /* Mountain */
  247.     {"m.s.t.", ZONE, 7 HRS},
  248.     {"mdt", DAYZONE, 7 HRS},
  249.     {"m.d.t.", DAYZONE, 7 HRS},
  250.     {"pst", ZONE, 8 HRS},        /* Pacific */
  251.     {"p.s.t.", ZONE, 8 HRS},
  252.     {"pdt", DAYZONE, 8 HRS},
  253.     {"p.d.t.", DAYZONE, 8 HRS},
  254.     {"yst", ZONE, 9 HRS},        /* Yukon */
  255.     {"y.s.t.", ZONE, 9 HRS},
  256.     {"ydt", DAYZONE, 9 HRS},
  257.     {"y.d.t.", DAYZONE, 9 HRS},
  258.     {"hst", ZONE, 10 HRS},        /* Hawaii */
  259.     {"h.s.t.", ZONE, 10 HRS},
  260.     {"hdt", DAYZONE, 10 HRS},
  261.     {"h.d.t.", DAYZONE, 10 HRS},
  262.  
  263.     {"gmt", ZONE, 0 HRS},
  264.     {"g.m.t.", ZONE, 0 HRS},
  265.     {"bst", DAYZONE, 0 HRS},        /* British Summer Time */
  266.     {"b.s.t.", DAYZONE, 0 HRS},
  267.     {"eet", ZONE, 0 HRS},        /* European Eastern Time */
  268.     {"e.e.t.", ZONE, 0 HRS},
  269.     {"eest", DAYZONE, 0 HRS},    /* European Eastern Summer Time */
  270.     {"e.e.s.t.", DAYZONE, 0 HRS},
  271.     {"met", ZONE, -1 HRS},        /* Middle European Time */
  272.     {"m.e.t.", ZONE, -1 HRS},
  273.     {"mest", DAYZONE, -1 HRS},    /* Middle European Summer Time */
  274.     {"m.e.s.t.", DAYZONE, -1 HRS},
  275.     {"wet", ZONE, -2 HRS },        /* Western European Time */
  276.     {"w.e.t.", ZONE, -2 HRS },
  277.     {"west", DAYZONE, -2 HRS},    /* Western European Summer Time */
  278.     {"w.e.s.t.", DAYZONE, -2 HRS},
  279.  
  280.     {"jst", ZONE, -9 HRS},        /* Japan Standard Time */
  281.     {"j.s.t.", ZONE, -9 HRS},    /* Japan Standard Time */
  282.                     /* No daylght savings time */
  283.  
  284.     {"aest", ZONE, -10 HRS},    /* Australian Eastern Time */
  285.     {"a.e.s.t.", ZONE, -10 HRS},
  286.     {"aesst", DAYZONE, -10 HRS},    /* Australian Eastern Summer Time */
  287.     {"a.e.s.s.t.", DAYZONE, -10 HRS},
  288.     {"acst", ZONE, -(9 HRS + HALFHR)},    /* Australian Central Time */
  289.     {"a.c.s.t.", ZONE, -(9 HRS + HALFHR)},
  290.     {"acsst", DAYZONE, -(9 HRS + HALFHR)},    /* Australian Central Summer */
  291.     {"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)},
  292.     {"awst", ZONE, -8 HRS},        /* Australian Western Time */
  293.     {"a.w.s.t.", ZONE, -8 HRS},    /* (no daylght time there, I'm told */
  294.     {0, 0, 0}};
  295.  
  296. struct table unittb[] = {
  297.     {"year", MUNIT, 12},
  298.     {"month", MUNIT, 1},
  299.     {"fortnight", UNIT, 14*24*60},
  300.     {"week", UNIT, 7*24*60},
  301.     {"day", UNIT, 1*24*60},
  302.     {"hour", UNIT, 60},
  303.     {"minute", UNIT, 1},
  304.     {"min", UNIT, 1},
  305.     {"second", SUNIT, 1},
  306.     {"sec", SUNIT, 1},
  307.     {0, 0, 0}};
  308.  
  309. struct table othertb[] = {
  310.     {"tomorrow", UNIT, 1*24*60},
  311.     {"yesterday", UNIT, -1*24*60},
  312.     {"today", UNIT, 0},
  313.     {"now", UNIT, 0},
  314.     {"last", NUMBER, -1},
  315.     {"this", UNIT, 0},
  316.     {"next", NUMBER, 2},
  317.     {"first", NUMBER, 1},
  318.     /* {"second", NUMBER, 2}, */
  319.     {"third", NUMBER, 3},
  320.     {"fourth", NUMBER, 4},
  321.     {"fifth", NUMBER, 5},
  322.     {"sixth", NUMBER, 6},
  323.     {"seventh", NUMBER, 7},
  324.     {"eigth", NUMBER, 8},
  325.     {"ninth", NUMBER, 9},
  326.     {"tenth", NUMBER, 10},
  327.     {"eleventh", NUMBER, 11},
  328.     {"twelfth", NUMBER, 12},
  329.     {"ago", AGO, 1},
  330.     {0, 0, 0}};
  331.  
  332. struct table milzone[] = {
  333.     {"a", ZONE, 1 HRS},
  334.     {"b", ZONE, 2 HRS},
  335.     {"c", ZONE, 3 HRS},
  336.     {"d", ZONE, 4 HRS},
  337.     {"e", ZONE, 5 HRS},
  338.     {"f", ZONE, 6 HRS},
  339.     {"g", ZONE, 7 HRS},
  340.     {"h", ZONE, 8 HRS},
  341.     {"i", ZONE, 9 HRS},
  342.     {"k", ZONE, 10 HRS},
  343.     {"l", ZONE, 11 HRS},
  344.     {"m", ZONE, 12 HRS},
  345.     {"n", ZONE, -1 HRS},
  346.     {"o", ZONE, -2 HRS},
  347.     {"p", ZONE, -3 HRS},
  348.     {"q", ZONE, -4 HRS},
  349.     {"r", ZONE, -5 HRS},
  350.     {"s", ZONE, -6 HRS},
  351.     {"t", ZONE, -7 HRS},
  352.     {"u", ZONE, -8 HRS},
  353.     {"v", ZONE, -9 HRS},
  354.     {"w", ZONE, -10 HRS},
  355.     {"x", ZONE, -11 HRS},
  356.     {"y", ZONE, -12 HRS},
  357.     {"z", ZONE, 0 HRS},
  358.     {0, 0, 0}};
  359.  
  360. lookup(id)
  361. char *id;
  362. {
  363. #define gotit (yylval=i->value,  i->type)
  364. #define getid for(j=idvar, k=id; *j++ = *k++; )
  365.  
  366.     char idvar[20];
  367.     register char *j, *k;
  368.     register struct table *i;
  369.     int abbrev;
  370.  
  371.     getid;
  372.     if (strlen(idvar) == 3) abbrev = 1;
  373.     else if (strlen(idvar) == 4 && idvar[3] == '.') {
  374.         abbrev = 1;
  375.         idvar[3] = '\0';
  376.     }
  377.     else abbrev = 0;
  378.  
  379.     if (islower(*idvar)) *idvar = toupper(*idvar);
  380.  
  381.     for (i = mdtab; i->name; i++) {
  382.         k = idvar;
  383.         for (j = i->name; *j++ == *k++;) {
  384.             if (abbrev && j==i->name+3) return gotit;
  385.             if (j[-1] == 0) return gotit;
  386.         }
  387.     }
  388.  
  389.     getid;
  390.     for (i = mztab; i->name; i++)
  391.         if (strcmp(i->name, idvar) == 0) return gotit;
  392.  
  393.     for (j = idvar; *j; j++)
  394.         if (isupper(*j)) *j = tolower(*j);
  395.     for (i=mztab; i->name; i++)
  396.         if (strcmp(i->name, idvar) == 0) return gotit;
  397.  
  398.     getid;
  399.     for (i=unittb; i->name; i++)
  400.         if (strcmp(i->name, idvar) == 0) return gotit;
  401.  
  402.     if (idvar[strlen(idvar)-1] == 's')
  403.         idvar[strlen(idvar)-1] = '\0';
  404.     for (i=unittb; i->name; i++)
  405.         if (strcmp(i->name, idvar) == 0) return gotit;
  406.  
  407.     getid;
  408.     for (i = othertb; i->name; i++)
  409.         if (strcmp(i->name, idvar) == 0) return gotit;
  410.  
  411.     getid;
  412.     if (strlen(idvar) == 1 && isalpha(*idvar)) {
  413.         if (isupper(*idvar)) *idvar = tolower(*idvar);
  414.         for (i = milzone; i->name; i++)
  415.             if (strcmp(i->name, idvar) == 0) return gotit;
  416.     }
  417.  
  418.     return(ID);
  419. }
  420.  
  421. #ifdef AMIGA
  422. struct fake_timeb { time_t time; long timezone; };
  423. # define TIME_T    struct fake_timeb
  424. #else
  425. # define TIME_T    struct timeb
  426. #endif /* AMIGA */
  427.  
  428. time_t getdate(p, now)
  429. char *p;
  430. TIME_T *now;
  431. {
  432. #define mcheck(f)    if (f>1) err++
  433.     time_t monthadd();
  434.     int err;
  435.     struct tm *lt;
  436.     time_t sdate, tod;
  437.     TIME_T ftz;
  438.  
  439.     lptr = p;
  440.     if (now == ((TIME_T *) NULL)) {
  441.         now = &ftz;
  442. #ifdef AMIGA
  443.         (void) time(&ftz);
  444.         now->timezone = timezone;
  445. #else
  446.         ftime(&ftz);
  447. #endif /* AMIGA */
  448.     }
  449.     lt = localtime(&now->time);
  450.     year = lt->tm_year;
  451.     month = lt->tm_mon+1;
  452.     day = lt->tm_mday;
  453.     relsec = 0; relmonth = 0;
  454.     timeflag = 0, zoneflag = 0, dateflag = 0, dayflag = 0, relflag = 0;
  455.     ourzone = now->timezone;
  456.     daylght = MAYBE;
  457.     hh = mm = ss = 0;
  458.     merid = 24;
  459.  
  460.     if (err = yyparse()) return (-1);
  461.  
  462.     mcheck(timeflag);
  463.     mcheck(zoneflag);
  464.     mcheck(dateflag);
  465.     mcheck(dayflag);
  466.  
  467.     if (err) return (-1);
  468.     if (dateflag || timeflag || dayflag) {
  469.         sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylght);
  470.         if (sdate < 0) return -1;
  471.     } else {
  472.         sdate = now->time;
  473.         if (relflag == 0)
  474.             sdate -= (lt->tm_sec + lt->tm_min*60 +
  475.                 lt->tm_hour*(60L*60L));
  476.     }
  477.     sdate += relsec;
  478.     sdate += monthadd(sdate, relmonth);
  479.  
  480.     if (dayflag && !dateflag) {
  481.         tod = dayconv(dayord, dayreq, sdate);
  482.         sdate += tod;
  483.     }
  484.     return sdate;
  485. }
  486.  
  487. void yyerror(s)
  488. char *s;
  489. {
  490.     return;
  491. }
  492.  
  493. yytabelem yyexca[] ={
  494. -1, 1,
  495.     0, -1,
  496.     -2, 0,
  497.     };
  498. # define YYNPROD 35
  499. # define YYLAST 220
  500. yytabelem yyact[]={
  501.  
  502.     12,    13,    21,     9,    14,    15,    16,    10,    11,    34,
  503.     17,    39,    40,    19,    38,    37,    36,    30,    29,    28,
  504.     26,    35,    31,    27,     8,     7,     6,     5,     4,     3,
  505.      2,     1,     0,     0,     0,     0,     0,     0,     0,     0,
  506.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  507.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  508.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  509.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  510.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  511.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  512.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  513.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  514.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  515.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  516.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  517.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  518.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  519.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  520.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  521.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  522.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  523.      0,    32,    33,    22,    20,    18,     0,    23,    24,    25 };
  524. yytabelem yypact[]={
  525.  
  526.  -1000,  -258, -1000, -1000, -1000, -1000, -1000,  -257, -1000,   -45,
  527.  -1000, -1000,  -241,   -21, -1000, -1000, -1000, -1000, -1000,  -242,
  528.  -1000,  -243,  -244, -1000, -1000, -1000,   -22, -1000,   -49,   -26,
  529.  -1000,  -245, -1000, -1000,  -246,  -247, -1000,  -249, -1000, -1000,
  530.  -1000 };
  531. yytabelem yypgo[]={
  532.  
  533.      0,    31,    30,    29,    28,    27,    26,    25,    24 };
  534. yytabelem yyr1[]={
  535.  
  536.      0,     1,     1,     2,     2,     2,     2,     2,     2,     8,
  537.      3,     3,     3,     3,     3,     3,     3,     4,     4,     6,
  538.      6,     6,     5,     5,     5,     5,     5,     5,     7,     7,
  539.      7,     7,     7,     7,     7 };
  540. yytabelem yyr2[]={
  541.  
  542.      0,     0,     4,     3,     3,     3,     3,     3,     2,     3,
  543.      5,     7,     9,     9,    11,    13,    13,     3,     3,     3,
  544.      5,     5,     7,    11,     5,     9,     5,     7,     5,     5,
  545.      5,     3,     3,     3,     5 };
  546. yytabelem yychk[]={
  547.  
  548.  -1000,    -1,    -2,    -3,    -4,    -5,    -6,    -7,    -8,   261,
  549.    265,   266,   258,   259,   262,   263,   264,   267,   260,    58,
  550.    259,    47,   258,   262,   263,   264,   261,    44,   261,   261,
  551.    261,    44,   260,   261,    58,    47,   261,   261,   261,   260,
  552.    261 };
  553. yytabelem yydef[]={
  554.  
  555.      1,    -2,     2,     3,     4,     5,     6,     7,     8,     9,
  556.     17,    18,     0,    19,    31,    32,    33,    34,    10,     0,
  557.     21,     0,    26,    28,    29,    30,    24,    20,    11,    22,
  558.     27,     0,    12,    13,     0,     0,    25,    14,    23,    15,
  559.     16 };
  560. typedef struct { char *t_name; int t_val; } yytoktype;
  561. #ifndef YYDEBUG
  562. #    define YYDEBUG    0    /* don't allow debugging */
  563. #endif
  564.  
  565. #if YYDEBUG
  566.  
  567. yytoktype yytoks[] =
  568. {
  569.     "ID",    257,
  570.     "MONTH",    258,
  571.     "DAY",    259,
  572.     "MERIDIAN",    260,
  573.     "NUMBER",    261,
  574.     "UNIT",    262,
  575.     "MUNIT",    263,
  576.     "SUNIT",    264,
  577.     "ZONE",    265,
  578.     "DAYZONE",    266,
  579.     "AGO",    267,
  580.     "-unknown-",    -1    /* ends search */
  581. };
  582.  
  583. char * yyreds[] =
  584. {
  585.     "-no such reduction-",
  586.     "timedate : /* empty */",
  587.     "timedate : timedate item",
  588.     "item : tspec",
  589.     "item : zone",
  590.     "item : dtspec",
  591.     "item : dyspec",
  592.     "item : rspec",
  593.     "item : nspec",
  594.     "nspec : NUMBER",
  595.     "tspec : NUMBER MERIDIAN",
  596.     "tspec : NUMBER ':' NUMBER",
  597.     "tspec : NUMBER ':' NUMBER MERIDIAN",
  598.     "tspec : NUMBER ':' NUMBER NUMBER",
  599.     "tspec : NUMBER ':' NUMBER ':' NUMBER",
  600.     "tspec : NUMBER ':' NUMBER ':' NUMBER MERIDIAN",
  601.     "tspec : NUMBER ':' NUMBER ':' NUMBER NUMBER",
  602.     "zone : ZONE",
  603.     "zone : DAYZONE",
  604.     "dyspec : DAY",
  605.     "dyspec : DAY ','",
  606.     "dyspec : NUMBER DAY",
  607.     "dtspec : NUMBER '/' NUMBER",
  608.     "dtspec : NUMBER '/' NUMBER '/' NUMBER",
  609.     "dtspec : MONTH NUMBER",
  610.     "dtspec : MONTH NUMBER ',' NUMBER",
  611.     "dtspec : NUMBER MONTH",
  612.     "dtspec : NUMBER MONTH NUMBER",
  613.     "rspec : NUMBER UNIT",
  614.     "rspec : NUMBER MUNIT",
  615.     "rspec : NUMBER SUNIT",
  616.     "rspec : UNIT",
  617.     "rspec : MUNIT",
  618.     "rspec : SUNIT",
  619.     "rspec : rspec AGO",
  620. };
  621. #endif /* YYDEBUG */
  622.  
  623. /*    @(#) yaccpar.src 1.2 88/10/25 
  624.  *
  625.  *    Copyright (C) The Santa Cruz Operation, 1985.
  626.  *    This Module contains Proprietary Information of
  627.  *    The Santa Cruz Operation, Microsoft Corporation
  628.  *    and AT&T, and should be treated as Confidential.
  629.  */
  630.  
  631. /*
  632. ** Skeleton parser driver for yacc output
  633. */
  634.  
  635. /*
  636. ** yacc user known macros and defines
  637. */
  638. #define YYERROR        goto yyerrlab
  639. #define YYACCEPT    return(0)
  640. #define YYABORT        return(1)
  641. #define YYBACKUP( newtoken, newvalue )\
  642. {\
  643.     if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  644.     {\
  645.         yyerror( "syntax error - cannot backup" );\
  646.         goto yyerrlab;\
  647.     }\
  648.     yychar = newtoken;\
  649.     yystate = *yyps;\
  650.     yylval = newvalue;\
  651.     goto yynewstate;\
  652. }
  653. #define YYRECOVERING()    (!!yyerrflag)
  654. #ifndef YYDEBUG
  655. #    define YYDEBUG    1    /* make debugging available */
  656. #endif
  657.  
  658. /*
  659. ** user known globals
  660. */
  661. int yydebug;            /* set to 1 to get debugging */
  662.  
  663. /*
  664. ** driver internal defines
  665. */
  666. #define YYFLAG        (-1000)
  667.  
  668. /*
  669. ** global variables used by the parser
  670. */
  671. YYSTYPE yyv[ YYMAXDEPTH ];    /* value stack */
  672. int yys[ YYMAXDEPTH ];        /* state stack */
  673.  
  674. YYSTYPE *yypv;            /* top of value stack */
  675. int *yyps;            /* top of state stack */
  676.  
  677. int yystate;            /* current state */
  678. int yytmp;            /* extra var (lasts between blocks) */
  679.  
  680. int yynerrs;            /* number of errors */
  681. int yyerrflag;            /* error recovery flag */
  682. int yychar;            /* current input token number */
  683.  
  684.  
  685.  
  686. /*
  687. ** yyparse - return 0 if worked, 1 if syntax error not recovered from
  688. */
  689. int
  690. yyparse()
  691. {
  692.     register YYSTYPE *yypvt;    /* top of value stack for $vars */
  693.  
  694.     /*
  695.     ** Initialize externals - yyparse may be called more than once
  696.     */
  697.     yypv = &yyv[-1];
  698.     yyps = &yys[-1];
  699.     yystate = 0;
  700.     yytmp = 0;
  701.     yynerrs = 0;
  702.     yyerrflag = 0;
  703.     yychar = -1;
  704.  
  705.     goto yystack;
  706.     {
  707.         register YYSTYPE *yy_pv;    /* top of value stack */
  708.         register int *yy_ps;        /* top of state stack */
  709.         register int yy_state;        /* current state */
  710.         register int  yy_n;        /* internal state number info */
  711.  
  712.         /*
  713.         ** get globals into registers.
  714.         ** branch to here only if YYBACKUP was called.
  715.         */
  716.     yynewstate:
  717.         yy_pv = yypv;
  718.         yy_ps = yyps;
  719.         yy_state = yystate;
  720.         goto yy_newstate;
  721.  
  722.         /*
  723.         ** get globals into registers.
  724.         ** either we just started, or we just finished a reduction
  725.         */
  726.     yystack:
  727.         yy_pv = yypv;
  728.         yy_ps = yyps;
  729.         yy_state = yystate;
  730.  
  731.         /*
  732.         ** top of for (;;) loop while no reductions done
  733.         */
  734.     yy_stack:
  735.         /*
  736.         ** put a state and value onto the stacks
  737.         */
  738. #if YYDEBUG
  739.         /*
  740.         ** if debugging, look up token value in list of value vs.
  741.         ** name pairs.  0 and negative (-1) are special values.
  742.         ** Note: linear search is used since time is not a real
  743.         ** consideration while debugging.
  744.         */
  745.         if ( yydebug )
  746.         {
  747.             register int yy_i;
  748.  
  749.             printf( "State %d, token ", yy_state );
  750.             if ( yychar == 0 )
  751.                 printf( "end-of-file\n" );
  752.             else if ( yychar < 0 )
  753.                 printf( "-none-\n" );
  754.             else
  755.             {
  756.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  757.                     yy_i++ )
  758.                 {
  759.                     if ( yytoks[yy_i].t_val == yychar )
  760.                         break;
  761.                 }
  762.                 printf( "%s\n", yytoks[yy_i].t_name );
  763.             }
  764.         }
  765. #endif /* YYDEBUG */
  766.         if ( ++yy_ps >= &yys[ YYMAXDEPTH ] )    /* room on stack? */
  767.         {
  768.             yyerror( "yacc stack overflow" );
  769.             YYABORT;
  770.         }
  771.         *yy_ps = yy_state;
  772.         *++yy_pv = yyval;
  773.  
  774.         /*
  775.         ** we have a new state - find out what to do
  776.         */
  777.     yy_newstate:
  778.         if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  779.             goto yydefault;        /* simple state */
  780. #if YYDEBUG
  781.         /*
  782.         ** if debugging, need to mark whether new token grabbed
  783.         */
  784.         yytmp = yychar < 0;
  785. #endif
  786.         if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  787.             yychar = 0;        /* reached EOF */
  788. #if YYDEBUG
  789.         if ( yydebug && yytmp )
  790.         {
  791.             register int yy_i;
  792.  
  793.             printf( "Received token " );
  794.             if ( yychar == 0 )
  795.                 printf( "end-of-file\n" );
  796.             else if ( yychar < 0 )
  797.                 printf( "-none-\n" );
  798.             else
  799.             {
  800.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  801.                     yy_i++ )
  802.                 {
  803.                     if ( yytoks[yy_i].t_val == yychar )
  804.                         break;
  805.                 }
  806.                 printf( "%s\n", yytoks[yy_i].t_name );
  807.             }
  808.         }
  809. #endif /* YYDEBUG */
  810.         if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  811.             goto yydefault;
  812.         if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )    /*valid shift*/
  813.         {
  814.             yychar = -1;
  815.             yyval = yylval;
  816.             yy_state = yy_n;
  817.             if ( yyerrflag > 0 )
  818.                 yyerrflag--;
  819.             goto yy_stack;
  820.         }
  821.  
  822.     yydefault:
  823.         if ( ( yy_n = yydef[ yy_state ] ) == -2 )
  824.         {
  825. #if YYDEBUG
  826.             yytmp = yychar < 0;
  827. #endif
  828.             if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  829.                 yychar = 0;        /* reached EOF */
  830. #if YYDEBUG
  831.             if ( yydebug && yytmp )
  832.             {
  833.                 register int yy_i;
  834.  
  835.                 printf( "Received token " );
  836.                 if ( yychar == 0 )
  837.                     printf( "end-of-file\n" );
  838.                 else if ( yychar < 0 )
  839.                     printf( "-none-\n" );
  840.                 else
  841.                 {
  842.                     for ( yy_i = 0;
  843.                         yytoks[yy_i].t_val >= 0;
  844.                         yy_i++ )
  845.                     {
  846.                         if ( yytoks[yy_i].t_val
  847.                             == yychar )
  848.                         {
  849.                             break;
  850.                         }
  851.                     }
  852.                     printf( "%s\n", yytoks[yy_i].t_name );
  853.                 }
  854.             }
  855. #endif /* YYDEBUG */
  856.             /*
  857.             ** look through exception table
  858.             */
  859.             {
  860.                 register int *yyxi = yyexca;
  861.  
  862.                 while ( ( *yyxi != -1 ) ||
  863.                     ( yyxi[1] != yy_state ) )
  864.                 {
  865.                     yyxi += 2;
  866.                 }
  867.                 while ( ( *(yyxi += 2) >= 0 ) &&
  868.                     ( *yyxi != yychar ) )
  869.                     ;
  870.                 if ( ( yy_n = yyxi[1] ) < 0 )
  871.                     YYACCEPT;
  872.             }
  873.         }
  874.  
  875.         /*
  876.         ** check for syntax error
  877.         */
  878.         if ( yy_n == 0 )    /* have an error */
  879.         {
  880.             /* no worry about speed here! */
  881.             switch ( yyerrflag )
  882.             {
  883.             case 0:        /* new error */
  884.                 yyerror( "syntax error" );
  885.                 goto skip_init;
  886.             yyerrlab:
  887.                 /*
  888.                 ** get globals into registers.
  889.                 ** we have a user generated syntax type error
  890.                 */
  891.                 yy_pv = yypv;
  892.                 yy_ps = yyps;
  893.                 yy_state = yystate;
  894.                 yynerrs++;
  895.             skip_init:
  896.             case 1:
  897.             case 2:        /* incompletely recovered error */
  898.                     /* try again... */
  899.                 yyerrflag = 3;
  900.                 /*
  901.                 ** find state where "error" is a legal
  902.                 ** shift action
  903.                 */
  904.                 while ( yy_ps >= yys )
  905.                 {
  906.                     yy_n = yypact[ *yy_ps ] + YYERRCODE;
  907.                     if ( yy_n >= 0 && yy_n < YYLAST &&
  908.                         yychk[yyact[yy_n]] == YYERRCODE)                    {
  909.                         /*
  910.                         ** simulate shift of "error"
  911.                         */
  912.                         yy_state = yyact[ yy_n ];
  913.                         goto yy_stack;
  914.                     }
  915.                     /*
  916.                     ** current state has no shift on
  917.                     ** "error", pop stack
  918.                     */
  919. #if YYDEBUG
  920. #    define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  921.                     if ( yydebug )
  922.                         printf( _POP_, *yy_ps,
  923.                             yy_ps[-1] );
  924. #    undef _POP_
  925. #endif
  926.                     yy_ps--;
  927.                     yy_pv--;
  928.                 }
  929.                 /*
  930.                 ** there is no state on stack with "error" as
  931.                 ** a valid shift.  give up.
  932.                 */
  933.                 YYABORT;
  934.             case 3:        /* no shift yet; eat a token */
  935. #if YYDEBUG
  936.                 /*
  937.                 ** if debugging, look up token in list of
  938.                 ** pairs.  0 and negative shouldn't occur,
  939.                 ** but since timing doesn't matter when
  940.                 ** debugging, it doesn't hurt to leave the
  941.                 ** tests here.
  942.                 */
  943.                 if ( yydebug )
  944.                 {
  945.                     register int yy_i;
  946.  
  947.                     printf( "Error recovery discards " );
  948.                     if ( yychar == 0 )
  949.                         printf( "token end-of-file\n" );
  950.                     else if ( yychar < 0 )
  951.                         printf( "token -none-\n" );
  952.                     else
  953.                     {
  954.                         for ( yy_i = 0;
  955.                             yytoks[yy_i].t_val >= 0;
  956.                             yy_i++ )
  957.                         {
  958.                             if ( yytoks[yy_i].t_val
  959.                                 == yychar )
  960.                             {
  961.                                 break;
  962.                             }
  963.                         }
  964.                         printf( "token %s\n",
  965.                             yytoks[yy_i].t_name );
  966.                     }
  967.                 }
  968. #endif /* YYDEBUG */
  969.                 if ( yychar == 0 )    /* reached EOF. quit */
  970.                     YYABORT;
  971.                 yychar = -1;
  972.                 goto yy_newstate;
  973.             }
  974.         }/* end if ( yy_n == 0 ) */
  975.         /*
  976.         ** reduction by production yy_n
  977.         ** put stack tops, etc. so things right after switch
  978.         */
  979. #if YYDEBUG
  980.         /*
  981.         ** if debugging, print the string that is the user's
  982.         ** specification of the reduction which is just about
  983.         ** to be done.
  984.         */
  985.         if ( yydebug )
  986.             printf( "Reduce by (%d) \"%s\"\n",
  987.                 yy_n, yyreds[ yy_n ] );
  988. #endif
  989.         yytmp = yy_n;            /* value to switch over */
  990.         yypvt = yy_pv;            /* $vars top of value stack */
  991.         /*
  992.         ** Look in goto table for next state
  993.         ** Sorry about using yy_state here as temporary
  994.         ** register variable, but why not, if it works...
  995.         ** If yyr2[ yy_n ] doesn't have the low order bit
  996.         ** set, then there is no action to be done for
  997.         ** this reduction.  So, no saving & unsaving of
  998.         ** registers done.  The only difference between the
  999.         ** code just after the if and the body of the if is
  1000.         ** the goto yy_stack in the body.  This way the test
  1001.         ** can be made before the choice of what to do is needed.
  1002.         */
  1003.         {
  1004.             /* length of production doubled with extra bit */
  1005.             register int yy_len = yyr2[ yy_n ];
  1006.  
  1007.             if ( !( yy_len & 01 ) )
  1008.             {
  1009.                 yy_len >>= 1;
  1010.                 yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  1011.                 yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  1012.                     *( yy_ps -= yy_len ) + 1;
  1013.                 if ( yy_state >= YYLAST ||
  1014.                     yychk[ yy_state =
  1015.                     yyact[ yy_state ] ] != -yy_n )
  1016.                 {
  1017.                     yy_state = yyact[ yypgo[ yy_n ] ];
  1018.                 }
  1019.                 goto yy_stack;
  1020.             }
  1021.             yy_len >>= 1;
  1022.             yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  1023.             yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  1024.                 *( yy_ps -= yy_len ) + 1;
  1025.             if ( yy_state >= YYLAST ||
  1026.                 yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
  1027.             {
  1028.                 yy_state = yyact[ yypgo[ yy_n ] ];
  1029.             }
  1030.         }
  1031.                     /* save until reenter driver code */
  1032.         yystate = yy_state;
  1033.         yyps = yy_ps;
  1034.         yypv = yy_pv;
  1035.     }
  1036.     /*
  1037.     ** code supplied by user is placed in this switch
  1038.     */
  1039.     switch( yytmp )
  1040.     {
  1041. case 3:
  1042. # line 35 "getdate.y"
  1043.  
  1044.         {timeflag++;} break;
  1045. case 4:
  1046. # line 37 "getdate.y"
  1047.  
  1048.         {zoneflag++;} break;
  1049. case 5:
  1050. # line 39 "getdate.y"
  1051.  
  1052.         {dateflag++;} break;
  1053. case 6:
  1054. # line 41 "getdate.y"
  1055.  
  1056.         {dayflag++;} break;
  1057. case 7:
  1058. # line 43 "getdate.y"
  1059.  
  1060.         {relflag++;} break;
  1061. case 9:
  1062. # line 47 "getdate.y"
  1063.  
  1064.         {if (timeflag && dateflag && !relflag) year = yypvt[-0];
  1065.         else {timeflag++;hh = yypvt[-0]/100;mm = yypvt[-0]%100;ss = 0;merid = 24;}} break;
  1066. case 10:
  1067. # line 51 "getdate.y"
  1068.  
  1069.         {hh = yypvt[-1]; mm = 0; ss = 0; merid = yypvt[-0];} break;
  1070. case 11:
  1071. # line 53 "getdate.y"
  1072.  
  1073.         {hh = yypvt[-2]; mm = yypvt[-0]; merid = 24;} break;
  1074. case 12:
  1075. # line 55 "getdate.y"
  1076.  
  1077.         {hh = yypvt[-3]; mm = yypvt[-1]; merid = yypvt[-0];} break;
  1078. case 13:
  1079. # line 57 "getdate.y"
  1080.  
  1081.         {hh = yypvt[-3]; mm = yypvt[-1]; merid = 24;
  1082.         daylght = STANDARD; ourzone = yypvt[-0]%100 + 60*yypvt[-0]/100;} break;
  1083. case 14:
  1084. # line 60 "getdate.y"
  1085.  
  1086.         {hh = yypvt[-4]; mm = yypvt[-2]; ss = yypvt[-0]; merid = 24;} break;
  1087. case 15:
  1088. # line 62 "getdate.y"
  1089.  
  1090.         {hh = yypvt[-5]; mm = yypvt[-3]; ss = yypvt[-1]; merid = yypvt[-0];} break;
  1091. case 16:
  1092. # line 64 "getdate.y"
  1093.  
  1094.         {hh = yypvt[-5]; mm = yypvt[-3]; ss = yypvt[-1]; merid = 24;
  1095.         daylght = STANDARD; ourzone = yypvt[-0]%100 + 60*yypvt[-0]/100;} break;
  1096. case 17:
  1097. # line 68 "getdate.y"
  1098.  
  1099.         {ourzone = yypvt[-0]; daylght = STANDARD;} break;
  1100. case 18:
  1101. # line 70 "getdate.y"
  1102.  
  1103.         {ourzone = yypvt[-0]; daylght = DAYLIGHT;} break;
  1104. case 19:
  1105. # line 73 "getdate.y"
  1106.  
  1107.         {dayord = 1; dayreq = yypvt[-0];} break;
  1108. case 20:
  1109. # line 75 "getdate.y"
  1110.  
  1111.         {dayord = 1; dayreq = yypvt[-1];} break;
  1112. case 21:
  1113. # line 77 "getdate.y"
  1114.  
  1115.         {dayord = yypvt[-1]; dayreq = yypvt[-0];} break;
  1116. case 22:
  1117. # line 80 "getdate.y"
  1118.  
  1119.         {month = yypvt[-2]; day = yypvt[-0];} break;
  1120. case 23:
  1121. # line 82 "getdate.y"
  1122.  
  1123.         {month = yypvt[-4]; day = yypvt[-2]; year = yypvt[-0];} break;
  1124. case 24:
  1125. # line 84 "getdate.y"
  1126.  
  1127.         {month = yypvt[-1]; day = yypvt[-0];} break;
  1128. case 25:
  1129. # line 86 "getdate.y"
  1130.  
  1131.         {month = yypvt[-3]; day = yypvt[-2]; year = yypvt[-0];} break;
  1132. case 26:
  1133. # line 88 "getdate.y"
  1134.  
  1135.         {month = yypvt[-0]; day = yypvt[-1];} break;
  1136. case 27:
  1137. # line 90 "getdate.y"
  1138.  
  1139.         {month = yypvt[-1]; day = yypvt[-2]; year = yypvt[-0];} break;
  1140. case 28:
  1141. # line 94 "getdate.y"
  1142.  
  1143.         {relsec +=  60L * yypvt[-1] * yypvt[-0];} break;
  1144. case 29:
  1145. # line 96 "getdate.y"
  1146.  
  1147.         {relmonth += yypvt[-1] * yypvt[-0];} break;
  1148. case 30:
  1149. # line 98 "getdate.y"
  1150.  
  1151.         {relsec += yypvt[-1];} break;
  1152. case 31:
  1153. # line 100 "getdate.y"
  1154.  
  1155.         {relsec +=  60L * yypvt[-0];} break;
  1156. case 32:
  1157. # line 102 "getdate.y"
  1158.  
  1159.         {relmonth += yypvt[-0];} break;
  1160. case 33:
  1161. # line 104 "getdate.y"
  1162.  
  1163.         {relsec++;} break;
  1164. case 34:
  1165. # line 106 "getdate.y"
  1166.  
  1167.         {relsec = -relsec; relmonth = -relmonth;} break;
  1168.     }
  1169.     goto yystack;        /* reset registers in driver code */
  1170. }
  1171.